﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Diagnostics;
using EpicBall.Levels;
namespace EpicBall.ScreenSystem
{
    public class MainMenu : MenuScreen
    {
        private Texture2D _title, _background, _newbtnTexture, _optionsbtnTexture, _exitbtnTexture, _indicator, _epicball;
        private Texture2D lvl1, lvl2, lvl3;
        private MenuButton newBtn, optionsBtn, exitBtn;
        private MenuButton level1btn, level2btn, level3btn;
        private float leftOffset;
        public MainMenu(int width, int height) : base(width, height) { }
        public override void LoadContent()
        {
            base.LoadContent();
            Vector2 centerPos = new Vector2(_screenWidth/2, _screenHeight/2);
            leftOffset = centerPos.X-480;
            Microsoft.Xna.Framework.Content.ContentManager content = GameStack.Content;
            _title = content.Load<Texture2D>("MainMenu/title");
            _background = content.Load<Texture2D>("backgrounds/space");
            //_newbtnTexture = content.Load<Texture2D>("MainMenu/newgame_btn");
            //_optionsbtnTexture = content.Load<Texture2D>("MainMenu/options_btn");
            lvl1 = content.Load<Texture2D>("MainMenu/level1btn");
            lvl2 = content.Load<Texture2D>("MainMenu/level2btn");
            lvl3 = content.Load<Texture2D>("MainMenu/level3btn");
            _exitbtnTexture = content.Load<Texture2D>("MainMenu/exit_btn");
            _epicball = content.Load<Texture2D>("MainMenu/epicball_mainmenu");
            _indicator = content.Load<Texture2D>("MainMenu/btn_indicator");
            //newBtn = new MenuButton(this, new Level1(), _newbtnTexture, new Vector2(leftOffset+_newbtnTexture.Width/2, 300));
            //optionsBtn = new MenuButton(this, new Level1(), _optionsbtnTexture, new Vector2(leftOffset + _optionsbtnTexture.Width/2, 342));
            level1btn = new MenuButton(this, new Level1(), lvl1, new Vector2(leftOffset + lvl1.Width / 2, 258));
            level2btn = new MenuButton(this, new Level2(), lvl2, new Vector2(leftOffset + lvl2.Width / 2, 300));
            level3btn = new MenuButton(this, new Level3(), lvl3, new Vector2(leftOffset + lvl3.Width / 2, 342));
            exitBtn = new ExitBtn(this, new Level1(), _exitbtnTexture, new Vector2(leftOffset+_exitbtnTexture.Width/2, 384));
            //AddMenuButton(newBtn);
            //AddMenuButton(optionsBtn);
            AddMenuButton(level1btn);
            AddMenuButton(level2btn);
            AddMenuButton(level3btn);
            AddMenuButton(exitBtn);
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            GameStack.SpriteBatch.Begin();
            GameStack.SpriteBatch.Draw(_background, new Rectangle(0, 0, _screenWidth, _screenHeight), Color.White);
            //GameStack.SpriteBatch.Draw(_title, new Rectangle((int)leftOffset, 158, _title.Width, _title.Height), Color.White);
            GameStack.SpriteBatch.Draw(_title, new Rectangle((int)leftOffset, 110, _title.Width, _title.Height), Color.White);
            GameStack.SpriteBatch.Draw(_epicball, new Rectangle((int)(_screenWidth/2),(int)(_screenHeight-_epicball.Height), _epicball.Width, _epicball.Height), Color.White);
            DrawHover();
            GameStack.SpriteBatch.End();
            base.Draw(gameTime);
        }

        public void DrawHover()
        {
            foreach (MenuButton m in menuBtns)
            {
                if (m.isHover)
                {
                    GameStack.SpriteBatch.Draw(_indicator, new Rectangle((int)(leftOffset - _indicator.Width - 10), (int)(m.Position.Y - _indicator.Height / 2), _indicator.Width, _indicator.Height), Color.White);
                }
            }
        }
    }
}
